package com.matt.foundation.vo;

import com.matt.domain.course.ChildrenCourse;
import com.matt.foundation.constant.ChildrenCourseConstant;
import com.matt.foundation.utils.DateUtil;
import lombok.Data;

import java.util.Date;
import java.util.Objects;


/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/9/9
 * *******************************
 */
@Data
public class ChildrenCourseListVo {
    private String childrenId;
    private String childrenCourseId;
    private String childrenName;
    private Integer month;
    private Integer allCourseNum = 0;
    private Integer leftCourseNum = 0;

    private Integer totalCourseSize = 0;
    private Integer overCourseSize = 0;
    private Integer evaluateCourseSize = 0;
    private Integer leaveCourseSize = 0;
    private Integer skipCourseSize = 0;

    private Integer status;

    public static ChildrenCourseListVo of(Object[] objects) {
        ChildrenCourseListVo vo = new ChildrenCourseListVo();
        vo.setChildrenId(objects[0] == null ? "" : objects[0].toString());
        vo.setChildrenName(objects[1] == null ? "" : objects[1].toString());
        vo.setMonth(objects[2] == null ? 0 : DateUtil.betweenMonths(new Date(), ((Date) objects[2])));
        vo.setAllCourseNum(objects[3] == null ? 0 : Integer.valueOf(objects[3].toString()));

        if (Objects.nonNull(objects[4])) {
            Integer leftCourse = Integer.valueOf(objects[4].toString());
            vo.setStatus(leftCourse > 0 ? ChildrenCourseConstant.Status.NORMAL.codeOf() : ChildrenCourseConstant.Status.END.codeOf());
            vo.setLeftCourseNum(leftCourse);
        }
        vo.setTotalCourseSize(objects[5] == null ? 0 : Integer.valueOf(objects[5].toString()));
        vo.setOverCourseSize(objects[6] == null ? 0 : Integer.valueOf(objects[6].toString()));
        vo.setEvaluateCourseSize(objects[7] == null ? 0 : Integer.valueOf(objects[7].toString()));
        vo.setLeaveCourseSize(objects[8] == null ? 0 : Integer.valueOf(objects[8].toString()));
        vo.setSkipCourseSize(objects[9] == null ? 0 : Integer.valueOf(objects[9].toString()));
        vo.setChildrenCourseId(objects[10] == null ? "" : objects[10].toString());

        vo.setStatus(objects[4] == null ? 0 : Integer.valueOf(objects[4].toString()));
        return vo;
    }
}
